package com.song.ssm.month.mapper;

import com.song.ssm.month.pojo.Role;
import com.song.ssm.month.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author 宋伟宁
 * @Date 2023/9/25
 * @Version 1.0
 **/
public interface UserMapper {

      User login(@Param("username") String username,@Param("password") String password);

      List<User> findUsers( User user);


      @Select("select * from t_role")
      List<Role> roles();

      @Select("select count(uid) from t_user where username=#{username}")
      int hashName(String username);

      @Insert("insert into t_user(username,password,realname,sex,birthday,status)" +
              " values(#{username},#{password},#{realname},#{sex},#{birthday},0)")
      @Options(useGeneratedKeys = true,keyProperty = "uid")
      int addUser(User user);

      @Update("update t_user set username=#{username},password=#{password},realname=#{realname},sex=#{sex},birthday=#{birthday} where uid=#{uid}")
      int updateUser(User user);

      int addMiddle(@Param("uid") int uid,@Param("split") String[] split);

      @Select("select * from t_user where uid=#{id}")
      @ResultMap("userMap")
      User findById(int id);

      @Update("update t_user set status= !status where uid=#{id}")
      boolean status(int id);

      @Select("SELECT rid from t_user_role where uid=#{uid}")
      List<Integer> findRoles(int uid);

      @Delete("delete  from t_user_role where uid=#{uid}")
      int deleteMiddle(int uid);



      int batch_middle(@Param("arr") String[] arr);

      int del_user(@Param("arr") String[] arr);
}
